package ${packagePrefix}.application.executor.${tableName?lower_case};

import ${packagePrefix}.application.assembler.${domainObjectName}Assembler;
import ${packagePrefix}.client.dto.data.${domainObjectName}DTO;
import ${packagePrefix}.client.dto.query.${domainObjectName}GetQry;
import ${packagePrefix}.domain.gateway.${domainObjectName}Gateway;
import ${packagePrefix}.domain.model.${tableName?lower_case}.${domainObjectName};
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import com.alibaba.cola.dto.SingleResponse;

import java.util.Optional;

/**
 * ${entityComment}查询执行器
 */
@Component
public class ${domainObjectName}GetQryExe {

    @Autowired
    private ${domainObjectName}Gateway ${domainObjectName?uncap_first}Gateway;

    @Autowired
    private ${domainObjectName}Assembler ${domainObjectName?uncap_first}Assembler;

    /**
     * 执行${entityComment}查询
     *
     * @param qry ${entityComment}查询对象
     * @return ${entityComment}DTO
     */
    public SingleResponse<${domainObjectName}DTO> execute(${domainObjectName}GetQry qry) {
        // 查询领域实体
        Optional<${domainObjectName}> ${domainObjectName?uncap_first}Optional = ${domainObjectName?uncap_first}Gateway.findById(qry.getId());
        
        // 如果不存在，返回空结果
        if (!${domainObjectName?uncap_first}Optional.isPresent()) {
            return SingleResponse.buildSuccess();
        }
        
        // 转换为DTO并返回
        ${domainObjectName} ${domainObjectName?uncap_first} = ${domainObjectName?uncap_first}Optional.get();
        ${domainObjectName}DTO dto = ${domainObjectName?uncap_first}Assembler.toDTO(${domainObjectName?uncap_first});
        
        return SingleResponse.of(dto);
    }
} 